// pages/setup/setup.js
const app = getApp()
var util = require('../../utils/util.js')
Page({

	/**
	 * 页面的初始数据
	 */
	data: {

	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		var that = this;
		that.getStoreInfo();
	
	},
	radioChange: function (e) {
		console.log('radio发生change事件，携带value值为：', e.detail.value)
		var that=this;
		this.setData({
			status: e.detail.value
		})
		
	},

	getStoreInfo: function () {
		var that = this;
		var that = this;
		util.showLoading();
		var apiUrl = '/api/store/store/index';
		var apiData = {};
		util.fetchPost(apiUrl, apiData, function (res) {
			util.hideLoading();
			if (res.state == 1) {
				that.setData({
					store_info: res.datas,		
				});
				if (res.datas.reduce_status==0){
					that.setData({
						status:0
					})
				}else{
					that.setData({
						status: 1
					})
				}
			} else {
				util.message(res.datas);
			}
		});
	},
	//提交
	formSubmit: function (e) {
		var that = this;
		var reduce_need = e.detail.value.reduce_need;
		var reduce_price = e.detail.value.reduce_price;
		if (that.data.status == 1) {
			if (reduce_need == "" || reduce_need == "0.00" || reduce_price == "" || reduce_price =="0.00") {
				util.showSuccess('请设置满减金额', 'none', false, 800);
				return;
			}
			

		}
		console.log(reduce_need < reduce_price, reduce_price, reduce_need);
		if (parseFloat(reduce_need) < parseFloat(reduce_price)) {
			util.showSuccess('减的金额不能超过满的金额哦', 'none', false, 800);
			return;
		}

		util.showLoading();
		util.fetchPost("/api/store/store/store_modify", {
			reduce_status: that.data.status,
			reduce_need: reduce_need,
			reduce_price: reduce_price
		}, function (res) {
			util.hideLoading();
			if (res.state == 1) {
				util.showSuccess(res.datas);
				setTimeout(function () {
					wx.navigateBack();
				}, 2000);
			} else {
				util.message(res.datas)
			}
		})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})